home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
TIME_ZON
/
GENROUTI.C
< prev
next >
Wrap
Text File
|
1991-11-08
|
4KB
|
257 lines
/* GenRoutines.c
* These routines are used variously by the different libraries.
*/
#include "CNameList.h"
#include <Global.h>
#include <GenRoutines.h>
#include <Packages.h>
#include <math.h>
/*
* This stuff is for my own access to SANE, and it's been around
* for awhile, so ignore it
*/
#define FLOATDECIMAL 0
#define FIXEDDECIMAL 1
typedef struct {
char style, unused;
short digits;
} decform;
typedef struct {
char sgn, unused;
short exp;
unsigned char sig[22];
} decimal;
decform gdecform;
decimal gdecimal;
#define odd(x) ((x)%2 ? TRUE : FALSE)
/***********************************/
/*
* This will put a little black outline around the first item of the
* dialog box, which should be OK
*/
pascal void
outline_ok(dlg,which)
DialogPtr dlg;
short which;
{
short type;
Handle item;
Rect box;
GetDItem(dlg,1,&type,&item,&box);
PenSize(3,3);
InsetRect(&box,-4,-4);
FrameRoundRect(&box,18,18);
}
/*
* This will install a procedure into a dialog as a certain item
* (For example the routine above)
*/
void
install_useritem(dlg,which,what)
DialogPtr dlg;
short which;
ProcPtr what;
{
short type;
Handle item;
Rect box;
GetDItem(dlg,which,&type,&item,&box);
SetDItem(dlg,which,type,what,&box);
}
/*
* My version of atof
*/
double
atofl(alpha)
char *alpha;
{
int index;
Boolean junk;
double dtemp;
index = 0;
asm {
MOVE.L alpha,-(SP)
PEA index
PEA gdecimal
PEA junk
MOVE.W #4,-(SP)
DC.W 0xA9EE
}
asm {
PEA gdecimal
PEA dtemp
MOVE.W #0x9,-(SP)
DC.W 0xA9EB
}
return(dtemp);
}
/*
* My version of ftoa
*/
char *
ftoa(numbr, str, decpl, expon)
double numbr;
char *str;
short decpl, expon;
{
Str255 junk;
gdecform.style = FIXEDDECIMAL;
gdecform.digits = decpl;
asm {
PEA gdecform
PEA numbr
PEA gdecimal
MOVE.W #0xB,-(SP)
DC.W 0xA9EB
}
asm {
PEA gdecform
PEA gdecimal
PEA junk
MOVE.W #3,-(SP)
DC.W 0xA9EE
}
strcpy(str,PtoCstr(&junk));
return(str);
}
void
copy_rectangle(r1,r2)
Rect *r1, *r2;
{
BlockMove((Ptr) r1, (Ptr) r2,sizeof(Rect));
}
/*
* The following routines are designed to handle input/output from
* editboxes in a dialog. They are not all used in Time Zone, but
* they can be handy.
*/
void
set_text(thedlg,which,thetext)
DialogPtr thedlg;
short which;
char *thetext;
{
short thetype;
Handle theitem;
Rect thebox;
char ptext[256];
strcpy(ptext,thetext);
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
SetIText(theitem, (Str255 *) CtoPstr(ptext));
}
void
get_text(thedlg,which,thetext)
DialogPtr thedlg;
short which;
char *thetext;
{
short thetype;
Handle theitem;
Rect thebox;
char mytext[256];
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
GetIText(theitem,(Str255 *) mytext);
while (mytext[mytext[0]] == ' ')
mytext[0]--;
strcpy(thetext,PtoCstr(mytext));
}
double
get_float(thedlg,which)
DialogPtr thedlg;
short which;
{
short thetype;
Handle theitem;
Rect thebox;
char ptext[256];
double atofl();
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
GetIText(theitem,(Str255 *) ptext);
return(atofl(PtoCstr(ptext)));
}
void
set_float(thedlg,which,theval,places)
DialogPtr thedlg;
short which;
double theval;
short places;
{
short thetype;
Handle theitem;
Rect thebox;
char ctext[256];
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
SetIText(theitem,(Str255 *) CtoPstr(ftoa(theval,ctext,places,0)));
}
short
get_radio(thedlg,which)
DialogPtr thedlg;
short which;
{
short thetype;
Handle theitem;
Rect thebox;
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
return(GetCtlValue((ControlHandle) theitem));
}
void
set_radio(thedlg,which,how)
DialogPtr thedlg;
short which, how;
{
short thetype;
Handle theitem;
Rect thebox;
GetDItem(thedlg,which,&thetype,&theitem,&thebox);
SetCtlValue((ControlHandle) theitem, Abs(how));
}